#include "DXUT.h"

#ifndef UPDATEQUEUE_H
#define UPDATEQUEUE_H

#include "Block.h"
#include <queue>
#include <set>

struct QueElement
{
	UINT64		Time;
	INTVECTOR4	Position;

	bool operator < (const  QueElement& rhs) const {
		return Time > rhs.Time;
	};
};

class Updatequeue {
private:
	std::priority_queue<QueElement>		m_Queue;
	std::set<INTVECTOR4>				m_Map;
	SRWLOCK								m_Lock;
	IWorld*								m_World;
	FILE*								m_file;
	UINT64								m_Tick;
protected:
	inline void enqueue(int x, int z, int y, byte type, UINT64 time);
	inline void enqueue(QueElement elem);
	inline QueElement dequeue();	
	inline QueElement top();
	bool   workBlock(QueElement elem);
	void save();
public:
	void load();
	Updatequeue(IWorld * world);
	~Updatequeue();
	void updateBlock(int x, int z, int y, byte type, UINT64 time);
	void updateBlock(QueElement elem);
	void work();

};

#endif